package com.bac.bacplatform;

import java.util.HashMap;
import java.util.Map;

import com.android.volley.Response.Listener;
import com.bac.utils.Config;
import com.bac.utils.Util;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class EmailActivity extends BaseActivity implements OnClickListener{
	private String new_emailString;
	private EditText newemailEditText;
	private Button confirmEmailButton;
	

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.email_address);
		findViewById(R.id.title_left).setOnClickListener(this);
	}

	@Override
	public void init() {
		newemailEditText = (EditText) findViewById(R.id.new_emailaddress);
		
		confirmEmailButton = (Button) findViewById(R.id.confirm_new_emailaddress);
		confirmEmailButton.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				ChangeEmail();
				
			}
		});

	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.title_left:
			finishActivityOut();
			break;
		default:
			break;
		}
	}
	
	public void ChangeEmail(){
		Listener<String> sl = new Listener<String>() {

			@Override
			public void onResponse(String response) {
				// TODO Auto-generated method stub
				dismissLoadingProgress();
				Log.i("TAG--success",response.toString());
				showToast("修改成功");
				Intent intent = new Intent(MainActivity.UPDATE_ACTION);
				sendBroadcast(intent);
			}
		};
		
		new_emailString = newemailEditText.getText().toString().trim();
		if (new_emailString.length() <=0 ) {
			showToast(R.string.input_new_emailaddress);
			return;
		}
		
		showLoadingProgress();
		String path = Config.URL_CHANGE_EMAIL_ADDRESS;
		Map<String, String> map = new HashMap<String, String>();
		map.put("email", new_emailString);
		Util.httpStringPost(path, sl, this, map);
	}

}
